<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-menu.tld" prefix="menu" %>
<%@ taglib uri="/WEB-INF/tlds/struts-menu-el.tld" prefix="menu-el" %>
<%@ taglib uri="/WEB-INF/tlds/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tlds/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tlds/authz.tld" prefix="authz" %>
<%@ taglib uri="/WEB-INF/tlds/sitemesh-decorator.tld" prefix="decorator"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" scope="request"/>
<script type="text/javascript" src="${ctx}/dwr/interface/VariableServiceDWR.js"></script>
<script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
<script type="text/javascript" src="${ctx}/dwr/util.js"></script>
<script type="text/javascript">
<!--

	function validateVar() {
		var name = $F("name");
		var value = $F("value");
		name=trim(name);
		value=trim(value);
		specName = unAllowedChars(name,'<bean:message key="allowedCharacters"/>');
		if(!name || name.length == 0) {
			alert('<bean:message key="error.keyFieldEmpty" />');
		} else if(!value || value.length == 0) {
			alert('<bean:message key="error.valueFieldEmpty" />');
		} else if(value.indexOf('"')>0) {
			alert('<bean:message key="error.variableValueContainsQuote" />');
		}else if(specName ){
			alert('<bean:message key="error.keyContainsSpecialCharacter" />'); 
		}  else {
			variable = { id:"", name:"", value:""};
			DWRUtil.getValues(variable);
			VariableServiceDWR.save(refreshAndClose,variable);
		}
	}
	function refreshAndClose(res) {
		if(res){
			alert('<bean:message key="error.nameAlreadyInUse" />');
			}
		else {
			this.opener.location = '${ctx}/variable.do?method=list';
			closePopup();
		}
	}
// -->	
</script>

<div id="subcontent">
	<html:form styleId="varForm" action="/variable" focus="name">
		<input type="hidden" id="method" name="method" value=""/>
		<html:hidden property="variable.id" styleId="id"/>
		<p> <bean:message key="variablePage.variableKey" /> : <html:text property="variable.name" styleId="name" maxlength="127"/> </p>
		<p> <bean:message key="variablePage.variableValue" /> : <html:text property="variable.value" styleId="value" maxlength="127"/> </p>
		<p> <input name="validateVarButton" type="submit" onclick="validateVar();return false;" value="<bean:message key='variablePage.validate' />"/>&nbsp;
			<input name="cancelVarButton" type="submit" onclick="closePopup();" value="<bean:message key='variablePage.cancel' />"/> </p>
	</html:form>
</div>